﻿using AutoMapper;
using MediatR;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;
using S.Organization.API.Application.Command.SheepFarmCommand;
using System.ComponentModel.DataAnnotations;

namespace S.Organization.API.Application.CommandHandler.SheepFarmCommandHandler
{
    public class DelSheepFarmCommandHandler : IRequestHandler<DelSheepFarmCommand, int>
    {
         private readonly IBaseRepository<SheepFarmSetting> _repository;
        private readonly IMapper mapper;

        public DelSheepFarmCommandHandler(IBaseRepository<SheepFarmSetting> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(DelSheepFarmCommand request, CancellationToken cancellationToken)
        {

            var list = await _repository.GetAllAsync();
            list=list.Where(x=>x.SheepFarmId==request.SheepFarmId).ToList();
            return await _repository.DeleteAsync(list);
       
        }


    }
}
